package com.qf.Servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Wy
 * @version V1.0
 * @Project day41-3
 * @Package ${PACKAGE_NAME}
 * @Description: ${TODO}
 * @Date 2022/5/17 13:21
 */
@WebServlet(name = "RegistServlet" ,urlPatterns = "/registServlet")
public class RegistServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.setCharacterEncoding("utf-8");
            response.setContentType("text/html; charset=UTF-8");
        //2. 获取页面传入的参数
        String name = request.getParameter("aa");
        //3. 判断以及实现业务
        String result=null;
        if(name.equals("root") || name.equals("admin")){
            //我们定义2代表该用户已经存在
            result="2";

        }else {
            //定义该用户可以注册
            result="1";
        }
        response.getWriter().write(result);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
               doPost(request,response);
    }
}
